package com.bdmc.web.controller.report;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.bdmc.common.annotation.Log;
import com.bdmc.common.core.controller.BaseController;
import com.bdmc.common.core.domain.PageQuery;
import com.bdmc.common.core.page.TableDataInfo;
import com.bdmc.common.core.validate.QueryGroup;
import com.bdmc.common.enums.BusinessType;
import com.bdmc.common.utils.poi.ExcelUtil;
import com.bdmc.work.domain.bo.WorkOrderBo;
import com.bdmc.work.domain.vo.WorkOrderSumVo;
import com.bdmc.work.service.IWorkOrderService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 车辆点火熄火控制器
 *
 * @author bdmc
 * @date 2022-08-08
 */
@Validated
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/report/workOrder")
public class ReportWorkOrderController extends BaseController {

    private final IWorkOrderService workOrderService;
    /**
     * 工单统计
     */
    @SaCheckPermission("report:workOrder:list")
    @GetMapping("/list")
    public TableDataInfo<WorkOrderSumVo> list(@Validated(QueryGroup.class) WorkOrderBo bo, PageQuery pageQuery) {
        return workOrderService.sumSelectPage(bo, pageQuery);
    }

    /**
     * 导出工单统计
     */
    @SaCheckPermission("report:workOrder:export")
    @Log(title = "导出工单统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@Validated WorkOrderBo bo, HttpServletResponse response) {
        List<WorkOrderSumVo> list = workOrderService.sumSelectPage(bo);
        ExcelUtil.exportExcel(list, "车辆点火、熄火统计", WorkOrderSumVo.class, response);
    }

}
